package com.kerrykidz.sales.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.dao.model.GblPosDiscountEntity;
import com.kerrykidz.sales.service.IDiscountService;
import com.kerrykidz.scminvoicing.dao.mapper.GblPosDiscountEntityMapper;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdEntity;
import com.kerrykidz.scminvoicing.service.IScmInvocingProductInfoService;

@Service
public class DiscountServiceImpl implements IDiscountService {

	@Autowired
	private IScmInvocingProductInfoService scmInvocingProductInfoService;

	@Autowired
	private GblPosDiscountEntityMapper gblPosDiscountEntityMapper;

	@Override
	public List<GblPosDiscountEntity> findDiscount() throws Exception {
		return this.scmInvocingProductInfoService.findAllDiscount();
		// final List<GblPosDiscountEntity> list = new
		// ArrayList<GblPosDiscountEntity>();
		// String sql = "SELECT * FROM GBL_POS_DISCOUNT WHERE DEL_FLAG=0";
		// this.jdbcTemplate.query(sql, new RowCallbackHandler() {
		//
		// @Override
		// public void processRow(ResultSet rs) throws SQLException {
		// GblPosDiscountEntity discount = new GblPosDiscountEntity();
		// discount.setPkDisId(rs.getString("PK_DIS_ID"));
		// discount.setDisDesc(rs.getString("DIS_DESC"));
		// discount.setDisValue(rs.getDouble("DIS_VALUE"));
		// list.add(discount);
		// }
		// });
		// return list;
	}

	@Override
	public GblPosDiscountEntity findDiscountByPk(String id) {
		return this.gblPosDiscountEntityMapper.findByPk(id);
	}

	@Override
	public double getGiftNoPrice(String[] prdIds, String branId) throws Exception {
		double price = 0d;
		for (String prdId : prdIds) {
			if (StringUtils.isNotBlank(prdId)) {
				GblScmPrdEntity prd = this.scmInvocingProductInfoService.getProductById(prdId, branId);
				price += prd.getProductPrice();
			}
		}
		return price;
	}
}
